package com.go8.mall.controller;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.go8.common.service.ServiceResponse;
import com.go8.sso.pojo.MemberAddress;
import com.go8.sso.service.MemberAddressService;

@Controller
public class MemberAddressController {
	@Autowired
	private MemberAddressService memberAddressService;
	
	@GetMapping("/address")
	public @ResponseBody Object getAddresses(long memberId){
		try {
			List<MemberAddress> addresses = memberAddressService.getAddresses(memberId);
			return ServiceResponse.ok(addresses);
		} catch (Exception e) {
			e.printStackTrace();
			return ServiceResponse.error();
		}
	}
	
	@PostMapping("/address/add")
	public @ResponseBody Object add(MemberAddress memberAddress){
		try {
			memberAddressService.add(memberAddress);
			return ServiceResponse.ok(memberAddress);
		} catch (Exception e) {
			e.printStackTrace();
			return ServiceResponse.error();
		}
	}
}
